﻿using System;
using System.Configuration;
using System.Data.Linq;

namespace Interactive.Utility.Linq {
    /// <summary>
    /// 泛型DataContext。添加Table属性
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class DataContext<T> : DataContext where T : class {
        public DataContext()
            : base(ConfigurationManager.ConnectionStrings["default"].ConnectionString){
#if DEBUG
            Log = Console.Out;
#endif
            SourceTable = GetTable<T>();
        }

        /// <summary>
        /// 构造函数,提供自定义的连接字符串
        /// </summary>
        /// <param name="connString">连接字符串</param>
        public DataContext(string connString)
            : base(connString){
            if (string.IsNullOrEmpty(connString))
                throw new ArgumentException("connString为空或Null,这是不允许的!", "connString");
            SourceTable = GetTable<T>();
        }

        public Table<T> SourceTable { get; private set; }
    }
}